from time import sleep

from base.base import Base
from page import y_web_ele as e_data


class PageWebExpress(Base):
    def __init__(self, url):
        super().__init__(url)

    # 点击网站管理菜单
    def click_web_manager_a(self):
        self.click(e_data.web_manager_menu)

    # 点击快递管理子菜单
    def click_express_manager(self):
        self.click(e_data.express_manager)

    # 进入iframe
    def to_iframe(self):
        self.go_iframe(e_data.iframe)

    # 点击新增按钮
    def click_express_add_butt(self):
        self.click(e_data.express_add_butt)

    # 新增——输入名称
    def input_add_name(self, value):
        self.input(e_data.input_express_add_district, value)

    # 新增——输入顺序
    def input_add_sequence(self, value):
        self.input(e_data.input_express_add_sequence, value)

    # 新增——选择是否启用
    def radio_add_use(self, mark):
        self.click(e_data.radio_express_add_use(mark))

    # 新增——点击保存
    def click_add_save(self):
        self.click(e_data.express_add_save_butt)

    # 移动到对应的tr
    def move_to_tr(self, num):
        self.hover(e_data.express_add_tbody_tr(num))

    # 点击行内编辑按钮
    """ 因为行内编辑中的元素与新增中的元素定位一样，可与新增公用方法 """

    def click_tr_edit_butt(self, num):
        self.click(e_data.express_tr_edit_butt(num))

    # 点击行内删除按钮
    def click_tr_delete(self, num):
        self.click(e_data.express_tr_delete_butt(num))
        sleep(1)
        self.click_delete_true()

    # 点击确认删除按钮
    def click_delete_true(self):
        self.click(e_data.express_delete_true)

    # 获取保存/编辑/删除提示信息
    def get_operation_info(self):
        return self.get_text(e_data.add_save_info)

    # 新增——流程
    def express_add_flow(self, name, sequence, is_use):
        sleep(1)
        self.click_express_add_butt()
        self.input_add_name(name)
        self.input_add_sequence(sequence)
        self.radio_add_use(is_use)
        self.click_add_save()
        sleep(1)
        return self.get_operation_info()

    # 删除——流程
    def express_delete_flow(self, num):
        sleep(1)
        self.move_to_tr(num)
        self.click_tr_delete(num)
        return self.get_operation_info()

# if __name__ == '__main__':
#     test = PageWebExpress('http://192.168.8.222/admin.php')
#     test.driver.add_cookie({
#         "name": "PHPSESSID",
#         "value": "lr7h3u496ve0ecmn39emks0imd"
#     })
#     test.driver.refresh()
#     test.click_web_manager_a()
#     test.click_express_manager()
#     test.to_iframe()
#     print(test.express_add_flow())
#     print(test.express_delete_flow(19))
